package com.wc.AlgoOJ.LQ1004_糖果;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/1/29 22:00
 * @description http://43.138.190.70:8888/p/LQ1004
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 110, M = 22;
    // f[i] 表示 i 状态下的最少的包数
    static int[] f = new int[1 << M];
    static int n, m, k;
    static int[] a = new int[N];

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        k = sc.nextInt();

        for (int i = 1; i <= n; i++) {
            int state = 0;
            for (int j = 1; j <= k; j++) {
                // 将该种类的糖加入状态 1 就是将 00001填入进去
                state |= 1 << (sc.nextInt() - 1);
            }
            a[i] = state;
        }
        // 最多也就是全带走嘛
        Arrays.fill(f, N);
        // 0 个 口味是不需要的糖果袋的
        f[0] = 0;
        // 01 背包问题
        for (int i = 1; i <= n; i++) {
            for (int j = (1 << m) - 1; j >= 0; j--) {
                // 到达这个状态，也就是f[j] 加上该袋糖果
                f[j | a[i]] = Math.min(f[j | a[i]], f[j] + 1);
            }
        }
        out.println(f[(1 << m) - 1] == N ? -1 : f[(1 << m) - 1]);
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}